package com.qidianit.mes.md.controller;

import com.qidianit.common.pojo.MESResult;
import com.qidianit.mes.md.service.UnitService;
import com.qidianit.mes.pojo.Unit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 奇幻夜之梦
 * @Company 起点编程
 * @Description
 * @Time 2024/10/17 17:14
 */
@CrossOrigin // 允许跨域请求
@RestController
@RequestMapping("/units")
public class UnitController {
    @Autowired
    private UnitService unitsService;
    @GetMapping("/list")
    public MESResult selectByPage(Unit unit,
                                  @RequestParam(defaultValue = "1")int page,
                                  @RequestParam(defaultValue = "10")int limit){
        // 这里只有一行代码，直接调用service，不处理任何业务
        return unitsService.selectByPage(unit,page,limit);
    }

    @PostMapping("/save")
    public MESResult save(@RequestBody Unit unit) {
        return  unitsService.save(unit);
    }

    @PutMapping("/update")
    public MESResult update(@RequestBody Unit unit) {
        return unitsService.updateUnit(unit);
    }

    @GetMapping("selectById")
    public MESResult selectById(Long unitId) {
        return unitsService.selectById(unitId);
    }

    @DeleteMapping("/delete")
    public MESResult delete(Long unitId){
        return unitsService.delete(unitId);
    }

    @DeleteMapping("/deletes")
    public MESResult deletes(String [] unitId){
        return unitsService.deletes(unitId);
    }

    @GetMapping("/listUnits")
    public MESResult listUnits() {
        return unitsService.listUnits();
    }
}

